package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.cbg.btn.TrslationBtn;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.until.TraslationTableUntil;
import org.come.Frame.ZhuFrame;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import com.tool.tcpimg.UIUtils;

 

/**
 * 我的藏宝阁指定购买面板
 * 
 * @author Administrator
 * 
 */

public class TraslationMyMainZhidinggoumaiJpanel extends JPanel {


    /**
     * 页码
     */
    private JLabel yema;

    /**
     * 页码按钮，首页，末页 , 左箭头, 右箭头
     */
    private TrslationBtn shouye, moye, leftArrows, rightArrows;

    /**
     * 当前页码 最大页码
     *
     */
    private int dangqianyeshu = 1, zuidayema = 50;

    // private JTable jTable;
    private JScrollPane jScrollPane;

    public TraslationMyMainZhidinggoumaiJpanel() {

        this.setPreferredSize(new Dimension(760, 460));
        this.setOpaque(false);
        this.setLayout(null);

        jScrollPane = new JScrollPane();
        jScrollPane.setOpaque(false);
        jScrollPane.setBounds(8, 62-27, 750, 375+27);
        jScrollPane.setBorder(null);
        TraslationTableUntil.TableModel(jScrollPane, 10);

        this.add(jScrollPane);

        /**
         * 页码设置
         */
        yema = new JLabel(dangqianyeshu + "/" + zuidayema);
        yema.setBounds(258+91, 442, 58, 17);
        yema.setForeground(UIUtils.COLOR_cbg8);
        yema.setOpaque(false);

        yema.setHorizontalAlignment(SwingConstants.CENTER);
        this.add(yema);

        shouye = new TrslationBtn("inkImg/number/b4/fy1.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        shouye.setBounds(287, 442, 40, 20);
        this.add(shouye);
        shouye.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != 1) {
                    dangqianyeshu = 1;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取当前页数(点击我的货物按钮页数默认为1)
                     * 2、转换为对应协议的json对象 3、发送给服务器处理数据信息
                     */
                    String sendmes = Agreement.getAgreement().searchAppointAgreement(dangqianyeshu + "");
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(10);
                    SendMessageUntil.toServer(sendmes);

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在首页");
                }
            }
        });

        leftArrows = new TrslationBtn("inkImg/number/b4/fy2.png", 1);
        leftArrows.setBounds(326, 442, 19, 20);
        this.add(leftArrows);
        leftArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu > 1) {
                    dangqianyeshu--;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取当前页数(点击我的货物按钮页数默认为1)
                     * 2、转换为对应协议的json对象 3、发送给服务器处理数据信息
                     */
                    String sendmes = Agreement.getAgreement().searchAppointAgreement(dangqianyeshu + "");
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(10);
                    SendMessageUntil.toServer(sendmes);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有上一页了");
                }
            }
        });

        moye = new TrslationBtn("inkImg/number/b4/fy4.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        moye.setBounds(433, 442, 40, 20);
        this.add(moye);

        moye.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != zuidayema) {
                    dangqianyeshu = zuidayema;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取当前页数(点击我的货物按钮页数默认为1)
                     * 2、转换为对应协议的json对象 3、发送给服务器处理数据信息
                     */
                    String sendmes = Agreement.getAgreement().searchAppointAgreement(dangqianyeshu + "");
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(10);
                    SendMessageUntil.toServer(sendmes);

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在末页");
                }
            }
        });

        rightArrows = new TrslationBtn("inkImg/number/b4/fy3.png", 1);
        rightArrows.setBounds(411, 442, 19, 20);
        this.add(rightArrows);
        rightArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu < zuidayema) {
                    dangqianyeshu++;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取当前页数(点击我的货物按钮页数默认为1)
                     * 2、转换为对应协议的json对象 3、发送给服务器处理数据信息
                     */
                    String sendmes = Agreement.getAgreement().searchAppointAgreement(dangqianyeshu + "");
                    SendMessageUntil.toServer(sendmes);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有下一页了");
                }
            }
        });
    }

    public void setPage(int zuidayema) {
        this.zuidayema = zuidayema;
        yema.setText(dangqianyeshu + "/" + zuidayema);
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);

        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/wdddxq.png");

        }
        g.drawImage(icon.getImage(), 0, 5, 760, 28,  this);

    }

    public JLabel getYema() {
        return yema;
    }

    public void setYema(JLabel yema) {
        this.yema = yema;
    }

    public int getDangqianyeshu() {
        return dangqianyeshu;
    }

    public void setDangqianyeshu(int dangqianyeshu) {
        this.dangqianyeshu = dangqianyeshu;
    }

    public int getZuidayema() {
        return zuidayema;
    }

    public void setZuidayema(int zuidayema) {
        this.zuidayema = zuidayema;
    }

    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public TrslationBtn getShouye() {
        return shouye;
    }

    public void setShouye(TrslationBtn shouye) {
        this.shouye = shouye;
    }

    public TrslationBtn getMoye() {
        return moye;
    }

    public void setMoye(TrslationBtn moye) {
        this.moye = moye;
    }

    public TrslationBtn getLeftArrows() {
        return leftArrows;
    }

    public void setLeftArrows(TrslationBtn leftArrows) {
        this.leftArrows = leftArrows;
    }

    public TrslationBtn getRightArrows() {
        return rightArrows;
    }

    public void setRightArrows(TrslationBtn rightArrows) {
        this.rightArrows = rightArrows;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

}
